# The class WorkoutDataFile defines the method of get test data from the
# coresponding test data file.
require 'win32ole'
class Excel
    def initialize(filepath)
        @excel = WIN32OLE.new("excel.application")
        @excel.visible = false
        @workbook = @excel.workbooks.open(filepath)
    end

    def close
        @data=nil
        @workbook.close
        @excel.Quit()
    end

    def get_column_data(column_num, start_row)
        @data=[]
        while @worksheet.range("a#{start_row}").value
            cell_data = @worksheet.range("#{column_num}#{start_row}").value
            if !cell_data.nil?
                @data << cell_data
            else
                @data << ""
            end
            start_row += 1
        end
        return @data
    end
end

module SalesData
    ORG_SEARCH_START_ROW = 3
    CONTACTS_START_ROW = 4
    class OrgSearch < Excel
        def initialize(filepath)
            super(filepath)
            @worksheet=@workbook.worksheets(2)
        end

        def get_search_in_data
            get_column_data("a",ORG_SEARCH_START_ROW)
        end

         def get_for_data
            get_column_data("b", ORG_SEARCH_START_ROW)
        end

        def get_market_data
            get_column_data("c", ORG_SEARCH_START_ROW)
        end

    end
#    class Contacts < Excel
#      def initialize(filepath)
#            super(filepath)
#            @worksheet=@workbook.worksheets(2)
#        end
#    end
end

begin
    org_search_data = SalesData::OrgSearch.new(File.dirname(__FILE__)+"\\..\\doc\\data\\testdata.xls")
    # puts org_search_data.get_search_in_data
    # puts org_search_data.get_for_data
    # puts org_search_data.get_market_data
rescue
    puts $!
    puts $@
ensure
    org_search_data.close unless org_search_data.nil?
end
#puts File.dirname(__FILE__)+"\\..\\..\\doc\\data\\"